home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / enscript.4 / enscript / enscript-1.4.0 / intl / explodename.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-13  |  4.2 KB  |  172 lines

  1. /* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
  4.  
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public License as
  7. published by the Free Software Foundation; either version 2 of the
  8. License, or (at your option) any later version.
  9.  
  10. The GNU C Library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. Library General Public License for more details.
  14.  
  15. You should have received a copy of the GNU Library General Public
  16. License along with the GNU C Library; see the file COPYING.LIB.  If
  17. not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  18. Boston, MA 02111-1307, USA.  */
  19.  
  20. #ifdef HAVE_CONFIG_H
  21. # include <config.h>
  22. #endif
  23.  
  24. #include <stdlib.h>
  25. #include <string.h>
  26.  
  27. #include "loadinfo.h"
  28.  
  29. int
  30. _nl_explode_name (name, language, modifier, territory, codeset,
  31.           normalized_codeset, special, sponsor, revision)
  32.      char *name;
  33.      const char **language;
  34.      const char **modifier;
  35.      const char **territory;
  36.      const char **codeset;
  37.      const char **normalized_codeset;
  38.      const char **special;
  39.      const char **sponsor;
  40.      const char **revision;
  41. {
  42.   enum { undecided, xpg, cen } syntax;
  43.   char *cp;
  44.   int mask;
  45.   
  46.   *modifier = NULL;
  47.   *territory = NULL;
  48.   *codeset = NULL;
  49.   *normalized_codeset = NULL;
  50.   *special = NULL;
  51.   *sponsor = NULL;
  52.   *revision = NULL;
  53.  
  54.   /* Now we determine the single parts of the locale name.  First
  55.      look for the language.  Termination symbols are `_' and `@' if
  56.      we use XPG4 style, and `_', `+', and `,' if we use CEN syntax.  */
  57.   mask = 0;
  58.   syntax = undecided;
  59.   *language = cp = name;
  60.   while (cp[0] != '\0' && cp[0] != '_' && cp[0] != '@'
  61.      && cp[0] != '+' && cp[0] != ',')
  62.     ++cp;
  63.  
  64.   if (*language == cp)
  65.     /* This does not make sense: language has to be specified.  Use
  66.        this entry as it is without exploding.  Perhaps it is an alias.  */
  67.     cp = strchr (*language, '\0');
  68.   else if (cp[0] == '_')
  69.     {
  70.       /* Next is the territory.  */
  71.       cp[0] = '\0';
  72.       *territory = ++cp;
  73.  
  74.       while (cp[0] != '\0' && cp[0] != '.' && cp[0] != '@'
  75.          && cp[0] != '+' && cp[0] != ',' && cp[0] != '_')
  76.     ++cp;
  77.  
  78.       mask |= TERRITORY;
  79.  
  80.       if (cp[0] == '.')
  81.     {
  82.       /* Next is the codeset.  */
  83.       syntax = xpg;
  84.       cp[0] = '\0';
  85.       *codeset = ++cp;
  86.  
  87.       while (cp[0] != '\0' && cp[0] != '@')
  88.         ++cp;
  89.  
  90.       mask |= XPG_CODESET;
  91.  
  92.       if (*codeset != cp && (*codeset)[0] != '\0')
  93.         {
  94.           *normalized_codeset = _nl_normalize_codeset (*codeset,
  95.                                cp - *codeset);
  96.           if (strcmp (*codeset, *normalized_codeset) == 0)
  97.         free ((char *) *normalized_codeset);
  98.           else
  99.         mask |= XPG_NORM_CODESET;
  100.         }
  101.     }
  102.     }
  103.  
  104.   if (cp[0] == '@' || (syntax != xpg && cp[0] == '+'))
  105.     {
  106.       /* Next is the modifier.  */
  107.       syntax = cp[0] == '@' ? xpg : cen;
  108.       cp[0] = '\0';
  109.       *modifier = ++cp;
  110.  
  111.       while (syntax == cen && cp[0] != '\0' && cp[0] != '+'
  112.          && cp[0] != ',' && cp[0] != '_')
  113.     ++cp;
  114.  
  115.       mask |= XPG_MODIFIER | CEN_AUDIENCE;
  116.     }
  117.  
  118.   if (syntax != xpg && (cp[0] == '+' || cp[0] == ',' || cp[0] == '_'))
  119.     {
  120.       syntax = cen;
  121.  
  122.       if (cp[0] == '+')
  123.     {
  124.        /* Next is special application (CEN syntax).  */
  125.       cp[0] = '\0';
  126.       *special = ++cp;
  127.  
  128.       while (cp[0] != '\0' && cp[0] != ',' && cp[0] != '_')
  129.         ++cp;
  130.  
  131.       mask |= CEN_SPECIAL;
  132.     }
  133.  
  134.       if (cp[0] == ',')
  135.     {
  136.        /* Next is sponsor (CEN syntax).  */
  137.       cp[0] = '\0';
  138.       *sponsor = ++cp;
  139.  
  140.       while (cp[0] != '\0' && cp[0] != '_')
  141.         ++cp;
  142.  
  143.       mask |= CEN_SPONSOR;
  144.     }
  145.  
  146.       if (cp[0] == '_')
  147.     {
  148.        /* Next is revision (CEN syntax).  */
  149.       cp[0] = '\0';
  150.       *revision = ++cp;
  151.  
  152.       mask |= CEN_REVISION;
  153.     }
  154.     }
  155.  
  156.   /* For CEN sytnax values it might be important to have the
  157.      separator character in the file name, not for XPG syntax.  */
  158.   if (syntax == xpg)
  159.     {
  160.       if (*territory != NULL && (*territory)[0] == '\0')
  161.     mask &= ~TERRITORY;
  162.  
  163.       if (*codeset != NULL && (*codeset)[0] == '\0')
  164.     mask &= ~XPG_CODESET;
  165.  
  166.       if (*modifier != NULL && (*modifier)[0] == '\0')
  167.     mask &= ~XPG_MODIFIER;
  168.     }
  169.  
  170.   return mask;
  171. }
  172.